home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / PredatorPrey.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  26.6 KB  |  1,065 lines  |  [TEXT/KAHL]

  1. /*    search for this pattern…    */
  2.     /* <------look at this!    */
  3. /*    and this pattern    */
  4.     /* cw5 */
  5. /*    and this pattern    */
  6.     /*    look at this    */
  7.     /*    cur defined in Globals.c    */
  8.  
  9. /****************************************************************************************/
  10. /*                            PredatorPrey Network Game                                    */
  11. /*                            James C. Ullrey                                                */
  12. /*                            INRESCO                                                        */
  13. /*                            © 1995                                                        */
  14. /*                            Version    3.97a                                                */
  15. /*                                                                                        */
  16. /*                            Use LJ Courier 10, tabs 2                                    */
  17. /*                                                                                        */
  18. /****************************************************************************************/
  19. /*                                                                                        */
  20. /*            Version History:                                                            */
  21. /*                                                                                        */
  22. /*                                                                                        */
  23. /*    Sunday        05/14/95    Separated Flight Simulator from Calculator Program            */
  24. /*                                                                                        */
  25. /*                                                                                        */
  26. /*    */
  27. /*    */
  28. /*    */
  29. /*    */
  30. /****************************************************************************************/
  31. /*    Current place of activity:                                                            */
  32. /*                                                                                        */
  33. /*                    /*    look for this error    */                /*                            */
  34. /*                    /* error?bug? */                        /*                            */
  35. /*    Things to do: in the matrix buttons there is sto plus code to be written            */
  36. /*                    underneath sqrt button likewise                                        */
  37. /*                    search for (gState & sWait)                                            */
  38. /*                                                                                        */
  39. /*                    search for (gState & matrix)                                        */
  40. /*                                                                                        */
  41. /*                the matrix buttons need code for the non-User mode                        */
  42. /*                                                                                        */
  43. /*                /*    here is my place    */            /*                                    */
  44. /*    use Courier 9 bold to display matrix elements with the List Manager windows            */
  45. /*    */
  46. /*                                                                                        */
  47. /****************************************************************************************/
  48.  
  49. #pragma mark end_history
  50.  
  51. /*****************************************************************/
  52. /*  I N C L U D E S
  53. /*****************************************************************/
  54. #include    <Quickdraw.h>
  55. #ifndef __GLO__
  56. #include "Globals.h"
  57. #endif
  58. #ifndef __C14__
  59. #include    "PredatorPrey.h"
  60. #endif
  61. #ifndef __CUP__
  62. #include    "calc_update.h"
  63. #endif
  64. #ifndef __CMO__
  65. #include    "calc_mousedown.h"
  66. #endif
  67.  
  68.  
  69. #include    <string.h>
  70. #ifndef __EVL__
  71. #include     "EventLoop.h"
  72. #endif
  73. #ifndef __DOS__
  74. #include     "DoScrap.h"
  75. #endif
  76. #ifndef __RED__
  77. #include     "ResourceDefs.h"
  78. #endif
  79. #ifndef __C14D__
  80. #include     "PredatorPreyData.h"
  81. #endif
  82. #ifndef __CIN__
  83. #include    "calc_inits.h"
  84. #endif
  85. #ifndef __CFL__
  86. #include     "calc_files.h"
  87. #endif
  88. #ifndef __DIS__
  89. #include    "Dispatcher.h"
  90. #endif
  91. #ifndef __HCP__
  92. #include    "HelpCloseProc.h"
  93. #endif
  94. #ifndef __HDP__
  95. #include    "HelpDrawProc.h"
  96. #endif
  97. #ifndef __HGP__
  98. #include     "HelpGetProc.h"
  99. #endif
  100. #ifndef __AEV__
  101. #include    "HelpWindowProc.h"
  102. #endif
  103.  
  104. #ifndef __MAP__
  105. #include    "myActionProc.h"
  106. #endif
  107. #ifndef __MCL__
  108. #include    "myClickLoop.h"
  109. #endif
  110. #ifndef __WW__
  111. #include    "WhichWindow.h"
  112. #endif
  113. /*#include    "AEvent.h"*/
  114. #ifndef __FIM__
  115. #include    "FileM.h"
  116. #endif
  117. /*#include    "GetMyHelpProc.h"*/
  118. #ifndef __HE__
  119. #include    "Help.h"
  120. #endif
  121. #ifndef __MWI__
  122. #include    "MainWindow.h"
  123. #endif
  124. #ifndef __MIS__
  125. #include    "Miscellany.h"
  126. #endif
  127. #ifndef __SC__
  128. #include    "Scrolling.h"
  129. #endif
  130. #ifndef __WA__
  131. #include    "WindowAids.h"
  132. #endif
  133. #ifndef __WIN__
  134. #include    "Windowing.h"
  135. #endif
  136. /*#include    "calc_prog_list.h"*/
  137. #ifndef __CDO__
  138. #include    "calc_dork.h"
  139. #endif
  140. #ifndef __CCE__
  141. #include    "calc_contents.h"
  142. #endif
  143. #ifndef __TI__
  144. #include "trick.h"
  145. #endif
  146. #ifndef __CAC__
  147. #include    "calc_activate.h"
  148. #endif
  149. #ifndef __CCR__
  150. #include    "calc_controls.h"
  151. #endif
  152. #ifndef __CDI__
  153. #include     "calc_dipshit.h"
  154. #endif
  155.  
  156. #ifndef __DIA__
  157. #include    "DialogAids.h"
  158. #endif
  159. #include "MainMenu.h"
  160. #include "windows.h"
  161. /*#include <asm.h>*/
  162. /*#include <math881.c>*/
  163. #include "AEvent.h"    
  164.  
  165. /********************************************************************
  166. /*  G L O B A L   V A R I A B L E   D E C L A R A T I O N S
  167. /********************************************************************/
  168.  
  169. /*    #define NULL                '\0'    */
  170.  
  171. #define MaxPoints    2500
  172.  
  173.  
  174. #define DoneButton            1
  175. #define Field3                3
  176. #define Field4                4
  177. #define Field5                5
  178. #define Field6                6
  179.  
  180. /*extern    mapstruct    map;*/
  181.  
  182. WindowPtr            theWPtr = 0L;
  183. WindowPtr            theRunWPtr = 0L;
  184. CharsHandle            theCharsHndl;
  185. CharsHandle            theChars2Hndl;
  186.  
  187. ControlHandle        theVScroll         = 0L, theHScroll     = 0L;
  188. ControlHandle        theRunVScroll     = 0L, theRunHScroll = 0L;
  189.  
  190. char                changed;
  191. char                Rchanged;
  192. extern    int            defaultFont,defaultFontSize;
  193.  
  194. Str255             theFileName = "\pPredPreyData";
  195. Str255            bufferOne;
  196. Str255            bufferTwo;
  197. Str255            bufferTwe;
  198. /*static */short    theVRefNum;
  199. Cursor            fingerCursor;
  200. Cursor            questCursor;
  201. Cursor            arrow,waitCursor;
  202. /*Boolean            scrapDirty;*/
  203. /*int             errno;*/
  204. long            gInt[10],rTemp;
  205. long            prCount;                                                /**/
  206. long            gTime;
  207. StringPtr        theVolName;
  208. Ptr                gDsplyPtr;
  209. Ptr                mapPtr;
  210.  
  211. short            qRefNum;
  212. short            pRefNum;
  213. short            gErrorFlag/*    =    0*/;
  214. short            gWindowState;
  215. long            gsState;
  216. long            gState = 0x00000000;
  217. long            delayTime = 70;
  218. Boolean            gBroken;                
  219. short            gtoChs;
  220. short            goWhere;
  221. Boolean            gLoadProgEnabled = FALSE;
  222. double_t            gDSEbuffer,gISGbuffer;
  223. double_t            thisIsFucked;
  224. short            tries = 0;
  225. short            gVect1;
  226. short            gVect2;
  227. Boolean            gFirstTickGot = FALSE;
  228. Boolean            gSecondTickGot = FALSE;
  229. Boolean            gFirstCoordGot = FALSE;
  230. Boolean            gWhichCoordFirst = 1;
  231. unsigned    long    gFirstTick;
  232. unsigned    long    gSecondTick;
  233. Boolean            gGotVector;
  234. Boolean            hasPlot;
  235.  
  236. /* flags */
  237.  
  238. /*double        whichRegn,whichReg0n;*/
  239. long        posN;
  240. long        numN;
  241.  
  242. Boolean        oldWay            = TRUE;
  243. Boolean        useColor[7];
  244.  
  245. WindowPtr    gMy_windows[MY_WINDOW_MAX + 1];
  246. WindowPtr    lastPtr;
  247. WindowPtr    preyPtr;
  248. long        gWindow_count = 0;
  249. Ptr            gPre_allocated_block = NIL;
  250.  
  251. Rect        gArrow_box;
  252. Rect        gCircle_box;
  253. Rect        gSquare_box;
  254. Rect        gCube_box;
  255. Rect        gHouse_box;
  256. Rect        gBackGrnd_box;
  257.  
  258. Rect        gPalette_frame;
  259.  
  260. Rect        gXrotation_box;
  261. Rect        gYrotation_box;
  262. Rect        gZrotation_box;
  263. Rect        gNegXrotation_box;
  264. Rect        gNegYrotation_box;
  265. Rect        gNegZrotation_box;
  266. Rect        gXrot_text_box;
  267. Rect        gYrot_text_box;
  268. Rect        gZrot_text_box;
  269. Rect        gRot_OK_box;
  270. Rect        gRot_Cancel_box;
  271.  
  272. Rect        gRotation_frame;
  273.  
  274. Rect        gDoManyRotation_box;
  275.  
  276. Rect        gDoRotateLeft_box;
  277. Rect        gDoRotateRight_box;
  278. Rect        gDoRotateUp_box;
  279. Rect        gDoRotateDown_box;
  280. Rect        gDoMoveIn_box;
  281. Rect        gDoMoveOut_box;
  282.  
  283. Rect        gDoPitchUp_box;
  284. Rect        gDoPitchDn_box;
  285. Rect        gDoYawLft_box;
  286. Rect        gDoYawRt_box;
  287. Rect        gDoBankLft_box;
  288. Rect        gDoBankRt_box;
  289.  
  290. Rect        gMovement_frame;
  291. Rect        gPlaneControl_frame;
  292.  
  293. Rect        gXstretch_box;
  294. Rect        gYstretch_box;
  295. Rect        gZstretch_box;
  296. Rect        gNegXstretch_box;
  297. Rect        gNegYstretch_box;
  298. Rect        gNegZstretch_box;
  299. Rect        gXstr_text_box;
  300. Rect        gYstr_text_box;
  301. Rect        gZstr_text_box;
  302. Rect        gStr_OK_box;
  303. Rect        gStr_Cancel_box;
  304. Rect        gStretch_frame;
  305. Rect        gFirstCalcIcon,gSecondCalcIcon,gThirdCalcIcon;
  306. Rect        gFourthCalcIcon,gFifthCalcIcon,gSixthCalcIcon;
  307.  
  308. Boolean        gIsWizard;
  309. Boolean        stillWizard;
  310. Boolean        WizAttempt;
  311. Boolean        PassAttempt;
  312. Boolean        preRegistered = FALSE;
  313. Boolean        gHelpNot;
  314.  
  315.                 ListHandle        helpList;        /* handle for List Manager            */
  316.  
  317. long            helpLong;                        /* for help facility                */
  318. Rect            helpRect = {26,164, 214,398};    /* for help facility                */
  319. Handle            helpHandle;                        /* work handle for help                */
  320.  
  321. Point            nextTextPosit;                    /* Position of next text window        */
  322. /*RgnHandle        workRegionH;*/                    /* work handle for TE redraw        */
  323. struct    wTblStruct                                /* space for some window info        */
  324.         windTbl[windMax];                        /* table of many of the above        */
  325. long            qCount;
  326. short            iRefNum;
  327. double            aaa[MaxPoints][3];
  328. short            kNumMyHelpItems;
  329.  
  330.  
  331. /*****************************************************************/
  332. /*  P R O T O T Y P E S
  333. /*****************************************************************/
  334. extern    Boolean        UpdateWindow        (WindowPtr    whichWindow);
  335. //extern    void        UpdateMenus         (void);
  336.         void        main                (void);
  337.         void        MainLoop            (void);
  338.         void        HandleEvent            (long *innerSel,long *outerSel);
  339.         void         DoKeystroke            (void);
  340.         void        unload_world        (void);
  341. /*****************************************************************/
  342. /*****************************************************************/
  343. /*                                                                 */
  344. /* R O U T I N E S                                                 */
  345. /*                                                                 */
  346. /*****************************************************************/
  347. /*****************************************************************/
  348.  
  349.  
  350. /*****************************************************************/
  351. /*  m a i n   -   Start of main program.
  352. /*****************************************************************/
  353. /********************** Main ************************/
  354. void main(void)
  355.  
  356. {
  357.     iRefNum = CurResFile();
  358.     qCount = 0;
  359.     gStrCnt = 0;
  360.     gFormatFlag = 0;
  361.     gErrorFlag    = 0;
  362.     gIsWizard = TRUE;
  363.     stillWizard = FALSE;
  364.     hasPlot = FALSE;
  365.     
  366.  
  367.     init_ROM();                        /* call initialization routine    */
  368.     
  369.     
  370.     //#if GENERATINGCFM
  371.     //    DebugStr("\pGENERATINGCFM");
  372.     //#endif
  373.     
  374.     /*    *------------- in calc_inits.c    */
  375.     /*    |                                */
  376.     /*    v                                */
  377.     GetEnvir( &theVRefNum );/* returns Volume ID (or working dir) of open System file */
  378.     DoGetSysConfig();
  379.     
  380.     SetUpCursors();                /* calc_inits.c */
  381.     InitScrap();
  382.     InitGlobals();
  383.     //UseResFile(iRefNum);
  384.     #ifdef    quiet
  385.         ;
  386.     #else
  387.         SplashScreen ();            /* calc_inits.c */
  388.         DoTheShare();                /* calc_inits.c */
  389.     #endif
  390.     WindowInit();                /* calc_inits.c */
  391.     MenuBarInit();                /* calc_inits.c */
  392.     LoadPicture();                /* calc_inits.c    */
  393.     SetUpDragRect();            /* calc_inits.c */
  394.     SetUpFile        ( &theFileName,  &theVRefNum );    /*    In calc_files.c    *//* Str255 theFileName = "\pPredPreyData"; */
  395.     
  396.     //SetUpLogFile    ( 0, &theLogFileName, &theVRefNum );                /*    In calc_files.c    */
  397.     
  398.     DoShareCopy();                /* in calc_dipshit.c */
  399.  
  400.     MainLoop();
  401. }
  402.  
  403.  
  404.  
  405. /*****************************************************************/
  406. /******************** unload_world *******************************/
  407. /*****************************************************************/
  408.  
  409. void    unload_world(void)
  410.  
  411. {
  412.     UnloadSeg(inits_seg);
  413.     
  414.     UnloadSeg(one_button_seg);
  415.     UnloadSeg(three_button_seg);
  416.     UnloadSeg(five_button_seg);
  417.     UnloadSeg(seven_button_seg);
  418.     UnloadSeg(nine_button_seg);
  419.     UnloadSeg(decimal_button_seg);
  420.     UnloadSeg(enter_button_seg);
  421.     UnloadSeg(sin_button_seg);
  422.     UnloadSeg(tan_button_seg);
  423.     UnloadSeg(sqrt_button_seg);
  424.     UnloadSeg(etox_button_seg);
  425.     UnloadSeg(tentox_button_seg);
  426.     UnloadSeg(ytox_button_seg);
  427.     UnloadSeg(inverse_button_seg);
  428.     UnloadSeg(rolldn_button_seg);
  429.     UnloadSeg(mousedown_seg);
  430.     UnloadSeg(activate_seg);        
  431.     UnloadSeg(update_seg);
  432.     UnloadSeg(handlebutton_seg);
  433.     UnloadSeg(memory_manager_seg);
  434.     UnloadSeg(matrix_funcs_seg);
  435.     UnloadSeg(arithmetic_seg);
  436.     UnloadSeg(help_seg);
  437.     UnloadSeg(program_seg);
  438.     UnloadSeg(dork_seg);        
  439.     UnloadSeg(dipshit_seg);        
  440.     UnloadSeg(wizard_seg);        
  441.     UnloadSeg(C14Data_seg);        
  442.     
  443.     UnloadSeg(contents_seg);                    /****/
  444.     UnloadSeg(controls_seg);                    /****/
  445.  
  446.     UnloadSeg(file_seg);
  447.     UnloadSeg(trick_seg);
  448.     UnloadSeg(HelpCloseSeg);
  449.     UnloadSeg(HelpDrawSeg);
  450.     UnloadSeg(HelpGetSeg);
  451.     UnloadSeg(HelpWindowSeg);
  452.     UnloadSeg(MouseDownSeg);
  453.     UnloadSeg(myActionSeg);
  454.     UnloadSeg(myClickLoopSeg);
  455.     UnloadSeg(WhichWindowSeg);
  456.     UnloadSeg(DispatcherSeg);
  457.     UnloadSeg(DoScrapSeg);
  458.     UnloadSeg(EventLoopSeg);
  459.     UnloadSeg(FileMSeg);
  460.     UnloadSeg(GlobalsSeg);
  461.     UnloadSeg(MainWindowSeg);
  462.     UnloadSeg(MiscellanySeg);
  463.     UnloadSeg(ScrollingSeg);
  464.     UnloadSeg(WindowAidsSeg);
  465.     UnloadSeg(WindowingSeg);
  466. /*    UnloadSeg(progList_seg);*/
  467.     
  468.     return;
  469.  
  470. }    /* end of unload_world()    */
  471.  
  472.  
  473.  
  474. /********************** MainLoop ************************/
  475. void    MainLoop(void)
  476. {
  477.     long    innerSel,outerSel;
  478.  
  479.  
  480.     gDone = FALSE;
  481.     gWNEImplemented = WNE_is_implemented();
  482.     
  483.     while( gDone == FALSE )
  484.     {
  485.         HandleEvent(&innerSel,&outerSel);
  486.     }
  487. }
  488.  
  489. /********************** HandleEvent ************************/
  490. void    HandleEvent(long *innerSel,long *outerSel)
  491. {
  492.     Boolean            result,ignore_result,fineMove = false;
  493.     short            myItemHit;
  494.     short            i,weapon_type;
  495.     char            theChar;
  496.     long            charCode;
  497.     KeyMap            theKeys;
  498.     WindowPtr        wizPtr;
  499.     GrafPtr            wOldPort;
  500.     short            itemHit,whichCalc;
  501.     long            dummy;
  502.     Point            pt;
  503. /* cw5 */    //SndListHandle    sound;
  504.     //Handle            Meep;
  505.     //SndListHandle    Jeep;
  506.     OSErr            errCode,iErr;
  507.     WindowPtr        wPtr;
  508.     WObjsHandle        w_objs_hndl;
  509.     SndChannelPtr    Chan00;
  510.     Boolean            quietNow = 0;
  511.     long            palSet;
  512.     short            vPtChoice,focalPtChoice;
  513.     
  514.     if(lastPtr != NIL)
  515.     {
  516.         w_objs_hndl = (WObjsHandle)GetWRefCon(lastPtr);
  517.     }
  518.     /**********************************************************/
  519.     
  520.     qCount++;
  521.     if(qCount >= 10)
  522.     {
  523.         qCount = 0;
  524.         if((wPtr = FrontWindow()) != NIL)
  525.         {
  526.             if(one_of_mine(wPtr) || wPtr == gRotateBox || wPtr == gStretchBox)
  527.             {
  528.                 *innerSel = 0;
  529.                 *outerSel = 0;
  530.                 if((**w_objs_hndl).arms_selected == 1 && (**w_objs_hndl).hasTargets)
  531.                 {
  532.                     TrackTarget(innerSel,outerSel);
  533.                     if(*innerSel & 0x00111111)
  534.                     {
  535.                         Chan00 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  536.                         if(Chan00 != nil)
  537.                         {
  538.                             Chan00->qLength = stdQLength;
  539.                             iErr = SndNewChannel(&Chan00,sampledSynth,initMono,nil);
  540.                         }
  541. /* cw5 */                //Meep = GetResource ('snd ', 1410);
  542.                         //Jeep = (SndListHandle)Meep;
  543.                         //if (Meep != NULL)
  544.                         //{
  545.                         //    for(i = 0;i <=5;i++)
  546.                         //    {
  547.                         //        errCode = SndPlay (Chan00, Jeep, true);        //errCode = SndPlay (NULL, guns0, false);
  548.                         //        Delay(3L,&dummy);
  549.                         //    }
  550. /* cw5 */                //}
  551.                         iErr = SndDisposeChannel(Chan00,quietNow);
  552.                     }
  553.                     else if(*outerSel & 0x00111111 /* && *innerSel ^ 0x00111111*/)
  554.                     {
  555. /* cw5 */                //Meep = GetResource ('snd ', 1400);
  556. /* cw5 */                //SndPlay (NULL, Meep, false);
  557.                     }
  558.                 }
  559.             }
  560.         }
  561.     }
  562.     /**********************************************************/
  563.     if ( gWNEImplemented )
  564.     {
  565.         ignore_result = WaitNextEvent(    everyEvent,
  566.                                         &gTheEvent,
  567.                                         SLEEP,
  568.                                         NIL_MOUSE_REGION );
  569.     }        
  570.     else
  571.     {
  572.         SystemTask();
  573.         ignore_result = GetNextEvent(    everyEvent,
  574.                                         &gTheEvent );
  575.     }
  576.     wPtr = FrontWindow();
  577.  
  578.     switch ( gTheEvent.what )
  579.     {
  580.         case nullEvent:
  581.                 
  582.                 break;
  583.         case mouseDown:
  584.                 HandleMouseDown();        /*    calc_mousedown.c    */
  585.                 break;
  586.         case mouseUp:
  587.                 break;
  588.         case keyDown:
  589.         case autoKey:
  590.                 wPtr = FrontWindow();        /*FindWindow( gTheEvent.where, &wPtr );*/
  591.                 theChar = gTheEvent.message & charCodeMask;
  592.                 if ((( gTheEvent.modifiers & cmdKey )/* && ( gTheEvent.modifiers & optionKey )*/) != 0)
  593.                         HandleMenuChoice( MenuKey( theChar ) );
  594.                 else if((gTheEvent.modifiers & optionKey)&&(gTheEvent.modifiers & controlKey))
  595.                 {
  596.                     if ((theChar == 23))                    /* control-option-w */
  597.                     {
  598.                         GetMouse(&pt);
  599.                         if (PtInRect(pt, &gDivideRect ))
  600.                         {
  601.                             DoTheWiz();                        /* in calc_dipshit.c */
  602.                         }
  603.                     }
  604.                     if ((theChar == 16) && (gIsWizard))        /* control-option-p */
  605.                     {
  606.                         DoTheShare();                        /* in calc_inits.c */
  607.                     }
  608.                     if ((theChar == 19) && (gIsWizard))        /* control-option-s */
  609.                     {
  610.                         DoSetPassword();
  611.                     }
  612.                     if ((theChar == 25) && (stillWizard))        /* control-option-y */
  613.                     {
  614. /* cw5 */                    //sound = GetResource ('snd ', MutateID);
  615.                         //if (sound != NULL)
  616.                         //{
  617.                         //    errCode = SndPlay (NULL, sound, false);
  618. /* cw5 */                    //}    
  619.                         if(gIsWizard)
  620.                         {
  621.                             gIsWizard = FALSE;
  622.                             DelMenuItem( GetMHandle(FILE_MENU_ID), 6 );
  623.                             InsMenuItem( GetMHandle(FILE_MENU_ID), "\pLoad Program/L", 5 );
  624.                             DelMenuItem( GetMHandle(FILE_MENU_ID), 7 );
  625.                             InsMenuItem( GetMHandle(FILE_MENU_ID), "\pLoad Data/L", 6 );
  626.                         }
  627.                         else
  628.                         {    
  629.                             gIsWizard = TRUE;
  630.                             DelMenuItem( GetMHandle(FILE_MENU_ID), 6 );
  631.                             InsMenuItem( GetMHandle(FILE_MENU_ID), "\pOpen Program/L", 5 );
  632.                             DelMenuItem( GetMHandle(FILE_MENU_ID), 7 );
  633.                             InsMenuItem( GetMHandle(FILE_MENU_ID), "\pOpen Data/L", 6 );
  634.                         }
  635.                         if(!gLoadProgEnabled)
  636.                         {
  637.                             DisableItem(GetMHandle(FILE_MENU_ID), 6);
  638.                             DisableItem(GetMHandle(FILE_MENU_ID), 7);
  639.                         }
  640.                     }
  641.                     if((theChar == 96))
  642.                     {
  643.                         /* Do option-control-` */
  644.                     }
  645.                     
  646.                 }
  647.  
  648.                         /*    else if((gTheEvent.modifiers & optionKey)&&(gTheEvent.modifiers & cmdKey))*/
  649.                         /*    {*/
  650.                         /*    }*/
  651.  
  652.                 else
  653.                 {
  654.                     charCode = gTheEvent.message & charCodeMask;
  655.  
  656.                     switch(charCode)
  657.                     {
  658.                         case 9:                        /*    tab char    */
  659.                             wPtr = FrontWindow();
  660.                             if(one_of_mine(wPtr) || wPtr == gRotateBox || wPtr == gStretchBox)
  661.                             {
  662.                                 palSet = (**w_objs_hndl).paletteSetting;
  663.                                 if(palSet == CIRCLE_OBJ)
  664.                                 {
  665.                                     weapon_type = (**w_objs_hndl).armament_type;
  666.                                     if(weapon_type == 0) draw_palette(lastPtr);    /*    in calc_update.c    */
  667.                                     else if(weapon_type == 1)
  668.                                     {
  669.                                         if((**w_objs_hndl).arms_selected == 0)    (**w_objs_hndl).arms_selected = 1;
  670.                                         else if((**w_objs_hndl).arms_selected == 1) (**w_objs_hndl).arms_selected = 0;
  671.                                         draw_palette(lastPtr);    /*    in calc_update.c    */
  672.                                     }
  673.                                     else if (weapon_type == 2)
  674.                                     {
  675.                                         if((**w_objs_hndl).arms_selected == 0)    (**w_objs_hndl).arms_selected = 1;
  676.                                         else if((**w_objs_hndl).arms_selected == 1)    (**w_objs_hndl).arms_selected = 2;
  677.                                         else if((**w_objs_hndl).arms_selected == 2) (**w_objs_hndl).arms_selected = 0;
  678.                                         draw_palette(lastPtr);    /*    in calc_update.c    */
  679.                                     }
  680.                                 }
  681.                                 else if(palSet == SQUARE_OBJ)
  682.                                 {
  683.                                     vPtChoice = (**w_objs_hndl).vPtNo;
  684.                                     switch(vPtChoice)
  685.                                     {
  686.                                         case 0:
  687.                                             (**w_objs_hndl).xvPt = 100;
  688.                                             (**w_objs_hndl).yvPt = 100;
  689.                                             (**w_objs_hndl).vPtNo = 1;
  690.                                             break;
  691.                                         case 1:
  692.                                             (**w_objs_hndl).xvPt = 200;
  693.                                             (**w_objs_hndl).yvPt = 100;
  694.                                             (**w_objs_hndl).vPtNo = 2;
  695.                                             break;
  696.                                         case 2:
  697.                                             (**w_objs_hndl).xvPt = 300;
  698.                                             (**w_objs_hndl).yvPt = 100;
  699.                                             (**w_objs_hndl).vPtNo = 3;
  700.                                             break;
  701.                                         case 3:
  702.                                             (**w_objs_hndl).xvPt = 400;
  703.                                             (**w_objs_hndl).yvPt = 100;
  704.                                             (**w_objs_hndl).vPtNo = 4;
  705.                                             break;
  706.                                         case 4:
  707.                                             (**w_objs_hndl).xvPt = 500;
  708.                                             (**w_objs_hndl).yvPt = 100;
  709.                                             (**w_objs_hndl).vPtNo = 5;
  710.                                             break;
  711.                                         case 5:
  712.                                             (**w_objs_hndl).xvPt = 600;
  713.                                             (**w_objs_hndl).yvPt = 100;
  714.                                             (**w_objs_hndl).vPtNo = 6;
  715.                                             break;
  716.                                         case 6:
  717.                                             (**w_objs_hndl).xvPt = 100;
  718.                                             (**w_objs_hndl).yvPt = 200;
  719.                                             (**w_objs_hndl).vPtNo = 7;
  720.                                             break;
  721.                                         case 7:
  722.                                             (**w_objs_hndl).xvPt = 200;
  723.                                             (**w_objs_hndl).yvPt = 200;
  724.                                             (**w_objs_hndl).vPtNo = 8;
  725.                                             break;
  726.                                         case 8:
  727.                                             (**w_objs_hndl).xvPt = 300;
  728.                                             (**w_objs_hndl).yvPt = 200;
  729.                                             (**w_objs_hndl).vPtNo = 9;
  730.                                             break;
  731.                                         case 9:
  732.                                             (**w_objs_hndl).xvPt = 400;
  733.                                             (**w_objs_hndl).yvPt = 200;
  734.                                             (**w_objs_hndl).vPtNo = 10;
  735.                                             break;
  736.                                         case 10:
  737.                                             (**w_objs_hndl).xvPt = 500;
  738.                                             (**w_objs_hndl).yvPt = 200;
  739.                                             (**w_objs_hndl).vPtNo = 11;
  740.                                             break;
  741.                                         case 11:
  742.                                             (**w_objs_hndl).xvPt = 600;
  743.                                             (**w_objs_hndl).yvPt = 200;
  744.                                             (**w_objs_hndl).vPtNo = 12;
  745.                                             break;
  746.                                         case 12:
  747.                                             (**w_objs_hndl).xvPt = 100;
  748.                                             (**w_objs_hndl).yvPt = 300;
  749.                                             (**w_objs_hndl).vPtNo =13;
  750.                                             break;
  751.                                         case 13:
  752.                                             (**w_objs_hndl).xvPt = 200;
  753.                                             (**w_objs_hndl).yvPt = 300;
  754.                                             (**w_objs_hndl).vPtNo = 14;
  755.                                             break;
  756.                                         case 14:
  757.                                             (**w_objs_hndl).xvPt = 300;
  758.                                             (**w_objs_hndl).yvPt = 300;
  759.                                             (**w_objs_hndl).vPtNo = 15;
  760.                                             break;
  761.                                         case 15:
  762.                                             (**w_objs_hndl).xvPt = 400;
  763.                                             (**w_objs_hndl).yvPt = 300;
  764.                                             (**w_objs_hndl).vPtNo = 16;
  765.                                             break;
  766.                                         case 16:
  767.                                             (**w_objs_hndl).xvPt = 500;
  768.                                             (**w_objs_hndl).yvPt = 300;
  769.                                             (**w_objs_hndl).vPtNo = 17;
  770.                                             break;
  771.                                         case 17:
  772.                                             (**w_objs_hndl).xvPt = 600;
  773.                                             (**w_objs_hndl).yvPt = 300;
  774.                                             (**w_objs_hndl).vPtNo = 18;
  775.                                             break;
  776.                                         case 18:
  777.                                             (**w_objs_hndl).xvPt = 100;
  778.                                             (**w_objs_hndl).yvPt = 400;
  779.                                             (**w_objs_hndl).vPtNo = 19;
  780.                                             break;
  781.                                         case 19:
  782.                                             (**w_objs_hndl).xvPt = 200;
  783.                                             (**w_objs_hndl).yvPt = 400;
  784.                                             (**w_objs_hndl).vPtNo = 20;
  785.                                             break;
  786.                                         case 20:
  787.                                             (**w_objs_hndl).xvPt = 300;
  788.                                             (**w_objs_hndl).yvPt = 400;
  789.                                             (**w_objs_hndl).vPtNo = 21;
  790.                                             break;
  791.                                         case 21:
  792.                                             (**w_objs_hndl).xvPt = 400;
  793.                                             (**w_objs_hndl).yvPt = 400;
  794.                                             (**w_objs_hndl).vPtNo = 22;
  795.                                             break;
  796.                                         case 22:
  797.                                             (**w_objs_hndl).xvPt = 500;
  798.                                             (**w_objs_hndl).yvPt = 400;
  799.                                             (**w_objs_hndl).vPtNo = 23;
  800.                                             break;
  801.                                         case 23:
  802.                                             (**w_objs_hndl).xvPt = 600;
  803.                                             (**w_objs_hndl).yvPt = 400;
  804.                                             (**w_objs_hndl).vPtNo = 0;
  805.                                             break;
  806.                                     }
  807.                                     InvalRect(&lastPtr->portRect);
  808.                                     do_update(lastPtr);
  809.                                 }
  810.                                 else if(palSet == T_BACKGRND_OBJ || palSet == BACKGRND_OBJ)
  811.                                 {
  812.                                     focalPtChoice = (**w_objs_hndl).focalPtNo;
  813.                                     switch(focalPtChoice)
  814.                                     {
  815.                                         case 0:
  816.                                             (**w_objs_hndl).focalPtNo = 1;
  817.                                             (**w_objs_hndl).focalLn = 1000;
  818.                                             break;
  819.                                         case 1:
  820.                                             (**w_objs_hndl).focalPtNo = 2;
  821.                                             (**w_objs_hndl).focalLn = 500;
  822.                                             break;
  823.                                         case 2:
  824.                                             (**w_objs_hndl).focalPtNo = 3;
  825.                                             (**w_objs_hndl).focalLn = 400;
  826.                                             break;
  827.                                         case 3:
  828.                                             (**w_objs_hndl).focalPtNo = 4;
  829.                                             (**w_objs_hndl).focalLn = 300;
  830.                                             break;
  831.                                         case 4:
  832.                                             (**w_objs_hndl).focalPtNo = 5;
  833.                                             (**w_objs_hndl).focalLn = 200;
  834.                                             break;
  835.                                         case 5:
  836.                                             (**w_objs_hndl).focalPtNo = 6;
  837.                                             (**w_objs_hndl).focalLn = 100;
  838.                                             break;
  839.                                         case 6:
  840.                                             (**w_objs_hndl).focalPtNo = 7;
  841.                                             (**w_objs_hndl).focalLn = 50;
  842.                                             break;
  843.                                         case 7:
  844.                                             (**w_objs_hndl).focalPtNo = 8;
  845.                                             (**w_objs_hndl).focalLn = 20;
  846.                                             break;
  847.                                         case 8:
  848.                                             (**w_objs_hndl).focalPtNo = 9;
  849.                                             (**w_objs_hndl).focalLn = 10;
  850.                                             break;
  851.                                         case 9:
  852.                                             (**w_objs_hndl).focalPtNo = 0;
  853.                                             (**w_objs_hndl).focalLn = 10000;
  854.                                             break;
  855.                                     }
  856.                                     InvalRect(&lastPtr->portRect);
  857.                                     do_update(lastPtr);
  858.                                 }
  859.                             }
  860.                         
  861.                             break;
  862.                         case 32:                    /*    space bar    */
  863.                             wPtr = FrontWindow();
  864.                             if(one_of_mine(wPtr) || wPtr == gRotateBox || wPtr == gStretchBox)
  865.                                 FireGuns(innerSel,outerSel);        /*    calc_dork.c    */
  866.                             //if((**w_objs_hndl).arms_selected == 1)
  867.                             //    GuideMissle(innerSel,outerSel);        /*    calc_dork.c    */
  868.                             break;
  869.                     }
  870.                 }
  871.                 break;
  872.         case keyUp:
  873.                 break;
  874.         case activateEvt:
  875.                 do_activate( (WindowPtr) gTheEvent.message,
  876.                                 (gTheEvent.modifiers & activeFlag) != 0);
  877.                 break;    /* located in calc_activate.c    */
  878.         case kHighLevelEvent:
  879.             DoHighLevelEvent (&gTheEvent);
  880.             break;
  881.             
  882.         case updateEvt:
  883.                 if ( one_of_mine((WindowPtr)gTheEvent.message ))    /* one_of… in this file */
  884.                 {
  885.                     do_update((WindowPtr) gTheEvent.message); /* ie, if graphics window */
  886.                 }
  887.                 else if( (WindowPtr)gTheEvent.message == gRotateBox )
  888.                 {
  889.                     SetPort(gRotateBox);
  890.                     BeginUpdate(gRotateBox);
  891.                     do_rotation_subject(gRotateBox,fineMove);    /* in calc_contents.c    */
  892.                     EndUpdate(gRotateBox);
  893.                 }
  894.                 else if( (WindowPtr)gTheEvent.message == gStretchBox )
  895.                 {
  896.                     SetPort(gStretchBox);
  897.                     BeginUpdate(gStretchBox);
  898.                     do_stretch_subject(gStretchBox);
  899.                     EndUpdate(gStretchBox);
  900.                 }
  901.                 break;
  902.     }
  903.     unload_world();    /*    unlock any segments used in last event process    */
  904.     if(gPre_allocated_block == NIL)
  905.     {
  906.         gPre_allocated_block = NewPtr(sizeof(CWindowRecord));
  907.         if(gPre_allocated_block == NIL)
  908.         {
  909.             #ifdef      powerc
  910.                 StopAlert(OUT_OF_MEM,    (UniversalProcPtr)NIL);
  911.             #else
  912.                 StopAlert(OUT_OF_MEM,    0/*NULL*/);
  913.             #endif      /* powerc */
  914.         }
  915.     }
  916. }
  917. /********************** End of HandleEvent *********************/
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926. /********************** cat_strings ******************************/
  927. void    cat_strings(char *srce_str,char *dest_str,unsigned long    dest_max)
  928. /*short    dest_max;*/
  929. {
  930.     size_t    new_max;
  931.     
  932.     new_max = dest_max;
  933.     /* convert Pascal strings to C strings */
  934.     
  935.     srce_str = PtoCstr((StringPtr)srce_str);    /* p. 207 of User Manual */
  936.     dest_str = PtoCstr((StringPtr)dest_str);
  937.     
  938.     /* concatenate the source onto the destination */
  939.     
  940.     srce_str = strncat (dest_str, srce_str, dest_max);
  941.     
  942.     /* convert the C strings back to Pascal */
  943.     
  944. /*    srce_str = (char*)CtoPstr(&srce_str);*/
  945. /*    dest_str = (char*)CtoPstr(&dest_str);*/
  946.     srce_str = (char*)CtoPstr(srce_str); /*    here is a change */
  947.     //dest_str = (char*)CtoPstr(dest_str); /*    here is a change */
  948.     
  949. } /* end of cat_strings() */
  950.  
  951.  
  952. /********************** one_of_mine ******************************/
  953. short one_of_mine(WindowPtr    wPtr)
  954. {
  955.     short n;
  956.     
  957.     if(wPtr == NIL) return(0);
  958.     
  959.     for(n = 1; n < MY_WINDOW_MAX+1; n++)
  960.         if(gMy_windows[n] == wPtr)
  961.         {
  962.             lastPtr = wPtr;
  963.             return(n);
  964.         }
  965.     return(0);
  966.     
  967. }  /* end of one_of_mine()    */
  968.  
  969.  
  970. /********************* clip_4_palette ****************************/
  971. void    clip_4_palette(WindowPtr wPtr)
  972. {
  973.     RgnHandle     saved_clip, palette_clip, w_frame_clip;
  974.     Rect         draw_bounds;
  975.     short        doc_length, doc_width;
  976.  
  977.  
  978.     palette_clip = NewRgn();
  979.     RectRgn (palette_clip, &gPalette_frame);
  980.  
  981.     draw_bounds = wPtr->portRect;                    /*    set the drawing rect...    */
  982.     draw_bounds.right -= 15;
  983.     draw_bounds.bottom -= 15;
  984.     
  985.     w_frame_clip = NewRgn();
  986.     RectRgn (w_frame_clip, &draw_bounds);
  987.     
  988.     DiffRgn(w_frame_clip, palette_clip, w_frame_clip);    /*    subtract the two    */
  989.                         
  990.     SetClip(w_frame_clip);                                /*    set the clip region    */
  991.     
  992.     DisposeRgn(palette_clip);                            /*    clean-up            */
  993.     DisposeRgn(w_frame_clip);
  994.     
  995. }  /* end of clip_4_palette()    */
  996.  
  997.  
  998.  
  999. /********************** inval_object *****************************/
  1000. void inval_object(WindowPtr wPtr, short index)
  1001. {
  1002.     Point        offset;
  1003.     Rect        obj_rect;
  1004.     WObjsHandle    w_objs_hndl;
  1005.  
  1006.     /*************    Find size and location of the object            **********/
  1007.  
  1008.  
  1009.     w_objs_hndl  = (WObjsHandle)GetWRefCon(wPtr);
  1010.     offset   = (**w_objs_hndl).scrollAmount;
  1011.         
  1012.     obj_rect = (**w_objs_hndl).object[index].bounds;
  1013.     OffsetRect(&obj_rect, -offset.h, -offset.v);
  1014.     
  1015.     /*************    Let the update routine take care of it...        **********/
  1016.  
  1017.     InvalRect(&obj_rect);
  1018.     
  1019.     return;
  1020.     
  1021. }  /*  end of inval_object()    */
  1022.  
  1023.  
  1024. /*----------*/
  1025. void DoKeystroke    ()
  1026. {
  1027.     short            charCode;
  1028.     char            ch;
  1029.  
  1030.     charCode = gTheEvent.message & charCodeMask;
  1031.     ch = charCode;
  1032.     
  1033.     if ((gTheEvent.modifiers & cmdKey) != 0) {
  1034.         if (gTheEvent.what != autoKey) {
  1035.             DoMenu (MenuKey (ch));
  1036.             SysBeep (1);
  1037.         }
  1038.     } else {
  1039.         if (curWindow == NULL) {
  1040.             SysBeep (1);
  1041.         } else {
  1042.             TypeInWindow (ch);    /*    Dispatcher.c    */
  1043.         }
  1044.     }
  1045. } /*DoKeystroke*/
  1046.  
  1047.  
  1048. //************************************************************************
  1049.  
  1050. void died (char desc[255], int code, int ref)
  1051. {
  1052.     /* nasty error has occurred - report it and quit */
  1053.     int go;
  1054.     char a[50], b[50];
  1055.     
  1056.     CtoPstr (desc);
  1057.     NumToString (code, (StringPtr)a);
  1058.     NumToString (ref, (StringPtr)b);
  1059.     ParamText ((StringPtr)desc, (StringPtr)a, (StringPtr)b, NULL);
  1060.     go = Alert(131,NULL);
  1061.     ExitToShell();
  1062. }
  1063.  
  1064. //************************************************************************
  1065.